def code(b):
  if b == 1:
    return False
    test = True
    c = b - 1
    while c > 1:
        if not b % c:
            test = False
            break
        c -= 1
  return test
m = input()
abc = []
for j in range(len(m)):
    for c in range(j + 1, len(m) + 1):
        b = int(m[j:c])
        if code(b):
            abc += [b]
print(max(abc) if abc else 0)
